import nattyFetch from 'natty-fetch';

const { API_URL,MOCK_URL } = require(`./../config/${ENV}.json`);
const context = nattyFetch.context({
  mockUrlPrefix: MOCK_URL,
  urlPrefix: API_URL,
  mock: false,
  withCredentials: false,
  traditional: true,
  data: {
    _wx_token_: '',
    size: 8
  },
  timeout: 15000,
  // 请按照需要开启
  fit: function (response) {
    let ret = {
      success: response.success
    };
    if (ret.success) {
      ret.content = response.data;
    } else {
      ret.error = {
        message: response.msg
      }
    }
    return ret;
  }
});

context.create('WechatAPI', {

  //获取配置
  auth: {
    url: 'wechat/api/sign',
    method: 'POST',
    header: {
      'Content-Type': 'application/json;charset=utf-8'
    },
  },

  //获取用户信息
  getUser: {
    mock: false,
    url: 'wechat/get/user',
    method: 'GET',
  },

  //上传图片
  uploadMedia: {
    mock: false,
    timeout: 50000,
    url: 'wechat/upload/uploadMedia',
    method: 'POST',

  },

  //添加建议
  addSuggession: {
    mock: false,
    url: 'wechat/dgzs/addSuggession',
    timeout: 50000,
    method: 'POST',
  },


  //获取上传的意见列表
  loadSuggestionList: {
    mock: false,
    url: 'wechat/dgzs/page',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: response.success
      };
      if (ret.success) {
        ret.content = response.data;
      } else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //获取上传的意见列表
  loadLastSuggestionOneByType: {
    mock: false,
    url: 'wechat/dgzs/loadLastSuggestionByType',
    method: 'GET'
  },

  //根据标题搜索过去上传的意见
  searchSuggest: {
    mock: false,
    url: 'wechat/dgzs/page',
    method: 'GET'
  },

  //撤销指定的意见
  fallBackSuggestion: {
    mock: false,
    url: 'wechat/dgzs/fallBackSuggestion',
    method: 'POST',
  },

  //加载绿色工地main工程所需数据
  queryProjectOrder: {
    mock: false,
    url: 'wechat/lsgd/queryProjectOrder',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //加载绿色工地main天气状况数据
  queryWeatherInfo: {
    mock: false,
    url: 'wechat/lsgd/queryWeatherInfo',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //搜索工程列表
  seachConstruction: {
    mock: false,
    url: 'wechat/lsgd/seachConstruction',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //查询工程对应的工程详情
  equipmentDetail: {
    mock: false,
    url: 'wechat/lsgd/equipmentDetail',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //根据城市用区域排名pm2.5和噪音
  queryAvgByDistrict: {
    mock: false,
    url: 'wechat/lsgd/queryAvgByDistrict',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //根据城市查询当地的工程位置信息
  querypmapByCity: {
    mock: false,
    url: 'wechat/lsgd/querypmapByCity',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //根据编号查询当地的施工许可进度情况
  querysgxkjd: {
    mock: false,
    url: 'wechat/jdcx/querysgxkjd',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //根据编号查询当地的施工合同备案进度情况
  querysghtbajd: {
    mock: false,
    url: 'wechat/jdcx/querysghtbajd',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //根据编号查询当地的项目部人员变更进度情况
  queryxmbrybgjd: {
    mock: false,
    url: 'wechat/jdcx/queryxmbrybgjd',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //查询公示公告main数据
  queryGsggMain: {
    mock: false,
    url: 'wechat/gsgg/queryGsggMain',
    method: 'GET',
    fit: function (response) {
      let ret = {
        success: true
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.msg
        }
      }
      return ret;
    }
  },

  //搜索所有状态的代码和代码值
  getJdStatusDes: {
    mock: false,
    url: 'wechat/jdcx/querystatusDescription',
    method: 'GET'
  },

  //搜索所有状态的代码和代码值
  getGdPostion: {
    mock: false,
    url: 'http://restapi.amap.com/v3/geocode/regeo',
    method: 'GET',
    fit: function (response) {
      console.log(response);
      let ret = {
        success: response.status === '1' ? true : false
      };
      if (ret.success) {
        ret.content = response;
      }
      else {
        ret.error = {
          message: response.info
        }
      }
      return ret;
    }
  },


});


export default context.api;
